using System;
using System.Data;
using System.Collections.Generic;

namespace SERP.DAO{
	/********************************BEGIN SalaryRulesDAO****************************************/
	///<summary>
	/// <para>Author: Auto generated class by CSharp Code Generator v2.0</para>
	/// <para>Date:09/03/2013 19:09:04</para>
	/// <para>Class Name: SalaryRulesDAO</para>
	/// <para>Description: Class access to table SalaryRules in database. Coder should'nt code here.</para>
	///</summary>

	
	public partial class SalaryRulesDAO : DAOBase<SalaryRulesEntity>{


		#region Select functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateSelectOneCommand</para>
		/// <para>Input: SalaryRuleId</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectOneCommand(int SalaryRuleId){
			string strSQL="SELECT  [SalaryRuleId],[RuleName],[Note],[Status],[FromDay],[ToDay] FROM [SalaryRules]  WHERE [SalaryRules].[SalaryRuleId]=@SalaryRuleId";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@SalaryRuleId",SalaryRuleId);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: SelectOne</para>
		/// <para>Input: SalaryRuleId</para>
		/// <para>Output: SalaryRulesEntity</para>
		///</summary>
		public SalaryRulesEntity SelectOne(int SalaryRuleId){
			IDbCommand cmd=this.CreateSelectOneCommand(SalaryRuleId);
			return this.Select(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateSelectAllCommand</para>
		/// <para>Input: </para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllCommand(){
			string strSQL="SELECT  [SalaryRuleId],[RuleName],[Note],[Status],[FromDay],[ToDay] FROM [SalaryRules] ";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateSelectAllByKeyCommand</para>
		/// <para>Input: ColumnName,ColumnValue</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllByKeyCommand(string ColumnName,object Value){
			string strSQL="SELECT  [SalaryRuleId],[RuleName],[Note],[Status],[FromDay],[ToDay] FROM [SalaryRules]  WHERE [SalaryRules].["+ColumnName+"]=@ColumnName";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@ColumnName",Value);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: SelectAll</para>
		/// <para>Input: </para>
		/// <para>Output: List of SalaryRulesEntity</para>
		///</summary>
		public List<SalaryRulesEntity> SelectAll(){
			IDbCommand cmd=this.CreateSelectAllCommand();
			return this.SelectList(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: SelectAllDS</para>
		/// <para>Input: </para>
		/// <para>Output: DataSet</para>
		///</summary>
		public DataSet SelectAllDS(){
			IDbCommand cmd=this.CreateSelectAllCommand();
			return this.SelectDS(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateSelectAllFilterCommand</para>
		/// <para>Input: </para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllFilterCommand(string strFilter){
			string strSQL="SELECT  [SalaryRuleId],[RuleName],[Note],[Status],[FromDay],[ToDay] FROM [SalaryRules]  WHERE "+RemoveInjection(strFilter);
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateSelectAllByKeyFilterCommand</para>
		/// <para>Input: ColumnName,ColumnValue</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllByKeyFilterCommand(string strFilter,string ColumnName,object Value){
			string strSQL="SELECT  [SalaryRuleId],[RuleName],[Note],[Status],[FromDay],[ToDay] FROM [SalaryRules]  WHERE [SalaryRules].["+ColumnName+"]=@ColumnName AND "+RemoveInjection(strFilter);
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@ColumnName",Value);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: SelectAll</para>
		/// <para>Input: </para>
		/// <para>Output: List of SalaryRulesEntity</para>
		///</summary>
		public List<SalaryRulesEntity> SelectAllFilter(string strFilter){
			IDbCommand cmd=this.CreateSelectAllFilterCommand(strFilter);
			return this.SelectList(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: SelectAllDSFilter</para>
		/// <para>Input: </para>
		/// <para>Output: DataSet</para>
		///</summary>
		public DataSet SelectAllDSFilter(string strFilter){
			IDbCommand cmd=this.CreateSelectAllFilterCommand(strFilter);
			return this.SelectDS(cmd);
		}
		#endregion

		#region Insert functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateInsertCommand</para>
		/// <para>Input: SalaryRulesEntity</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateInsertCommand(SalaryRulesEntity o){
			string strSQL="INSERT INTO [SalaryRules]([RuleName],[Note],[Status],[FromDay],[ToDay]) VALUES  (@RuleName,@Note,@Status,@FromDay,@ToDay);SELECT  @@IDENTITY";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			if(o.IsNullRuleName)
				this.CreateCommandParameter(cmd,"@RuleName",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@RuleName",o.RuleName);

			if(o.IsNullNote)
				this.CreateCommandParameter(cmd,"@Note",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@Note",o.Note);

			if(o.IsNullStatus)
				this.CreateCommandParameter(cmd,"@Status",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@Status",o.Status);

			if(o.IsNullFromDay)
				this.CreateCommandParameter(cmd,"@FromDay",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@FromDay",o.FromDay);

			if(o.IsNullToDay)
				this.CreateCommandParameter(cmd,"@ToDay",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@ToDay",o.ToDay);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: Save</para>
		/// <para>Input: SalaryRulesEntity</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool Save(SalaryRulesEntity o){
			bool result=false;
			IDbCommand cmd=this.CreateInsertCommand(o);
			object id=this.ExecuteScalar(cmd,ref result);
			cmd.Dispose();
			try{
				o.SalaryRuleId=int.Parse(Convert.ToString(id));
			}
			catch{}
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: SaveList</para>
		/// <para>Input: List of SalaryRulesEntity</para>
		/// <para>Output: </para>
		///</summary>
		public void SaveList(List<SalaryRulesEntity>list){
			foreach(SalaryRulesEntity o in list){
				try{
					this.Save(o);
				}
				catch{
				}
			}
		}
		#endregion

		#region Update functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateUpdateCommand</para>
		/// <para>Input: SalaryRulesEntity</para>
		/// <para>Output: </para>
		///</summary>
		protected IDbCommand CreateUpdateCommand(SalaryRulesEntity o){
			string strSQL="UPDATE  [SalaryRules] SET [SalaryRules].[RuleName]=@RuleName,[SalaryRules].[Note]=@Note,[SalaryRules].[Status]=@Status,[SalaryRules].[FromDay]=@FromDay,[SalaryRules].[ToDay]=@ToDay WHERE [SalaryRules].[SalaryRuleId]=@SalaryRuleId";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			if(o.IsNullRuleName)
				this.CreateCommandParameter(cmd,"@RuleName",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@RuleName",o.RuleName);

			if(o.IsNullNote)
				this.CreateCommandParameter(cmd,"@Note",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@Note",o.Note);

			if(o.IsNullStatus)
				this.CreateCommandParameter(cmd,"@Status",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@Status",o.Status);

			if(o.IsNullFromDay)
				this.CreateCommandParameter(cmd,"@FromDay",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@FromDay",o.FromDay);

			if(o.IsNullToDay)
				this.CreateCommandParameter(cmd,"@ToDay",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@ToDay",o.ToDay);

			if(o.IsNullSalaryRuleId)
				this.CreateCommandParameter(cmd,"@SalaryRuleId",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@SalaryRuleId",o.SalaryRuleId);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateUpdateFieldCommand</para>
		/// <para>Input: ColumnName,ColumnValue,SalaryRuleId</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateUpdateFieldCommand(string ColumnName,object Value,int SalaryRuleId){
			string strSQL="UPDATE  [SalaryRules] SET [SalaryRules].["+ColumnName+"]=@ColumnName WHERE [SalaryRules].[SalaryRuleId]=@SalaryRuleId";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@SalaryRuleId",SalaryRuleId);



			this.CreateCommandParameter(cmd,"@ColumnName",Value);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: Update</para>
		/// <para>Input: SalaryRulesEntity</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool Update(SalaryRulesEntity o){
			IDbCommand cmd=this.CreateUpdateCommand(o);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: UpdateList</para>
		/// <para>Input: List of SalaryRulesEntity</para>
		/// <para>Output: </para>
		///</summary>
		public void UpdateList(List<SalaryRulesEntity>list){
			foreach(SalaryRulesEntity o in list){
				try{
					this.Update(o);
				}
				catch{
				}
			}
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: UpdateRuleName</para>
		/// <para>Input: NewRuleName,SalaryRuleId</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateRuleName(string NewRuleName,int SalaryRuleId){
			IDbCommand cmd=this.CreateUpdateFieldCommand("RuleName",NewRuleName,SalaryRuleId);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: UpdateNote</para>
		/// <para>Input: NewNote,SalaryRuleId</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateNote(string NewNote,int SalaryRuleId){
			IDbCommand cmd=this.CreateUpdateFieldCommand("Note",NewNote,SalaryRuleId);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: UpdateStatus</para>
		/// <para>Input: NewStatus,SalaryRuleId</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateStatus(Byte NewStatus,int SalaryRuleId){
			IDbCommand cmd=this.CreateUpdateFieldCommand("Status",NewStatus,SalaryRuleId);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: UpdateFromDay</para>
		/// <para>Input: NewFromDay,SalaryRuleId</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateFromDay(int NewFromDay,int SalaryRuleId){
			IDbCommand cmd=this.CreateUpdateFieldCommand("FromDay",NewFromDay,SalaryRuleId);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: UpdateToDay</para>
		/// <para>Input: NewToDay,SalaryRuleId</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateToDay(int NewToDay,int SalaryRuleId){
			IDbCommand cmd=this.CreateUpdateFieldCommand("ToDay",NewToDay,SalaryRuleId);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		#endregion

		#region Delete functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: DeleteAllCommand</para>
		/// <para>Input: </para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteAllCommand(){
			string strSQL="DELETE   FROM [SalaryRules]  ";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: DeleteCommand</para>
		/// <para>Input: SalaryRulesEntity</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteCommand(SalaryRulesEntity o){
			string strSQL="DELETE   FROM [SalaryRules]   WHERE [SalaryRules].[SalaryRuleId]=@SalaryRuleId";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			if(o.IsNullSalaryRuleId)
				this.CreateCommandParameter(cmd,"@SalaryRuleId",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@SalaryRuleId",o.SalaryRuleId);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: DeleteAll</para>
		/// <para>Input: </para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool DeleteAll(){
			IDbCommand cmd=this.CreateDeleteAllCommand();
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateDeleteByPrimaryKeyCommand</para>
		/// <para>Input: SalaryRuleId</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteByPrimaryKeyCommand(int SalaryRuleId){
			string strSQL="DELETE   FROM [SalaryRules]   WHERE [SalaryRules].[SalaryRuleId]=@SalaryRuleId";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@SalaryRuleId",SalaryRuleId);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateDeleteByKeyCommand</para>
		/// <para>Input: ColumnName , ColumnValue</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteByKeyCommand(string ColumnName,object Value){
			string strSQL="DELETE   FROM [SalaryRules]   WHERE [SalaryRules].["+ColumnName+"]=@ColumnName";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@ColumnName",Value);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: Delete</para>
		/// <para>Input: SalaryRulesEntity</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool Delete(SalaryRulesEntity o){
			IDbCommand cmd=this.CreateDeleteCommand(o);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: DeleteByID</para>
		/// <para>Input: SalaryRuleId</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool DeleteByID(int SalaryRuleId){
			IDbCommand cmd=this.CreateDeleteByPrimaryKeyCommand(SalaryRuleId);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		#endregion

		#region Select,delete by SalaryRuleId functions
		#endregion

		#region MapObject functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: MapObject</para>
		/// <para>Input: IDataReader</para>
		/// <para>Output: SalaryRulesEntity</para>
		///</summary>
		protected override SalaryRulesEntity MapObject(IDataReader r){
			SalaryRulesEntity entity = new SalaryRulesEntity();
			try{
				if(r.FieldCount>0){
					try
					{
						int ordinal = r.GetOrdinal("SalaryRuleId");
						if (!r.IsDBNull(ordinal)) entity.SalaryRuleId = ((int)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("RuleName");
						if (!r.IsDBNull(ordinal)) entity.RuleName = ((string)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("Note");
						if (!r.IsDBNull(ordinal)) entity.Note = ((string)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("Status");
						if (!r.IsDBNull(ordinal)) entity.Status = ((Byte)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("FromDay");
						if (!r.IsDBNull(ordinal)) entity.FromDay = ((int)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("ToDay");
						if (!r.IsDBNull(ordinal)) entity.ToDay = ((int)(r.GetValue(ordinal)));
					}
					catch{}
					return entity;
				}
			}catch{}
			return null;
		}
		#endregion
	}
	/*****************************************************************************************************/
	/**********************************END SalaryRulesDAOBase*****************************************/
	/*****************************************************************************************************/
}

